#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

class Solution {
    public:
        int maxSubArray(int A[], int n) {
            int max = INT_MIN;
            int curMax = 0;
            for (int i = 0; i < n; i++) {
                curMax += A[i];
                if (curMax > max) max = curMax;
                if (curMax < 0) curMax = 0;
            }
            return max;
        }
};

//test on 1337 online judge and pass all the test
int main(int argc, char **argv)
{
    Solution mySolution;

    cout << "-----------------Test 1--------------------" << endl;
    int input[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
    int result = mySolution.maxSubArray(input, sizeof(input)/sizeof(int));
    cout << result << endl;


    cout << "-----------------Test 2--------------------" << endl;


    cout << "-----------------Test 3--------------------" << endl;


    cout << "-----------------Test 4--------------------" << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
